<template>
  <div class="form-item">
    <label for="">{{title}}</label>
    <div class="item-content">
      <input v-model="val" :type="type" v-if="type" />
      <slot></slot>
    </div>
  </div>
</template>

<script>
export default {
  name: 'FormItem',
  props: {
    title: {
      type: String,
      default: ''
    },
    type: {
      type: String,
      default: ''
    },
    value: {
      default: ''
    }
  },
  data () {
    return {
      val: this.value
    }
  },
  watch: {
    value (newVal) {
      this.val = newVal
    },
    val (newVal) {
      this.$emit('input', newVal)
    }
  }
}
</script>

<style lang="scss" scoped>
.form-item {
  @include wh(100%, 100px);
  @include flex(row, center, center);
  @include border1px();
  max-height: auto;
  padding: 0 20px;
  box-sizing: border-box;
  label {
    flex-shrink: 0;
    font-size: $font-size-m;
    color: #ccc;
    display: flex;
    align-items: center;
    text-align: left;
  }
  .item-content {
    height: 100%;
    flex: 1;
    padding-left: 20px;
    input {
      display: block;
      border: 0;
      width: 100%;
      height: 100%;
      outline: none;
      text-align: right;
    }
    & > * {
      background: transparent;
    }
  }
}
</style>
